package com.yunhe.control;

import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import com.yunhe.bean.Board;
import com.yunhe.service.GoodsBoardService;
import com.yunhe.util.MySession;

/**
 * Servlet implementation class goodClassifyUpdate
 */
/*@WebServlet(name = "goodClassifyUpdate.do", urlPatterns = { "/goodClassifyUpdate.do" })*/
@WebServlet("/goodClassifyUpdate.do")
public class goodClassifyUpdate extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public goodClassifyUpdate() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doPost(request, response);
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		SqlSession se = new MySession().getSession();
		String bid = request.getParameter("boardId");
		
		String bname = request.getParameter("classifyName");
		
		System.out.println(bid+":"+bname);
		
		Board b = new Board(Integer.parseInt(bid),bname);
		
		boolean n = new GoodsBoardService().updateBoard(b);
		
		if(n) {
			se.update("com.yun.dao.GoodsBoardDao.updateBoard",b);
			se.commit();
			//request.getRequestDispatcher("getBoardClassify.do").forward(request,response);
			response.sendRedirect("getBoardClassify.do");
		}else {
			Writer writer=response.getWriter();
			writer.write("The new name has exited.Can't update!");
		}

		
	}

}
